package com.zchat.android.preferences;

import android.content.SharedPreferences;

import com.zchat.android.service_aidl_beans.User;
import com.zchat.api.util.ZChatSetting;


/**
 * 
 * @author Oliverzhu
 *	2012/6/15
 */
public class Preferences {
	private static final String TAG = "Preferences";
    private static final boolean DEBUG = ZChatSetting.DEBUG;
    
    public static final String PREFERENCE_ID = "id";
    
    /**登录用户名 */
    public static final String PREFERENCE_USER_NAME = "username";
    
    /**登录密码 */
    public static final String PREFERENCE_USER_PASSWORD = "userpassword";
    
    /**接受协议 */
    public static final String PREFERENCE_ACCEPT = "accept";
    
    public static final String PREFERENCE_HELP = "help";
    
    public static void setAcceptStatus(SharedPreferences preferences,String status)
    {
    	SharedPreferences.Editor editor=preferences.edit();  
    	editor.putString(PREFERENCE_ACCEPT, status);
    	editor.commit();
    }
    /**
     * 帮助页面
     */
    public static boolean getAcceptStatus(SharedPreferences preferences)
    {
    	if("yes".equals(preferences.getString(PREFERENCE_ACCEPT, "no")))
    	{
    		return true;
    	}
    	return false;
    }
    
    public static void setHelpStatus(SharedPreferences preferences,String status)
    {
    	SharedPreferences.Editor editor=preferences.edit();  
    	editor.putString(PREFERENCE_HELP, status);
    	editor.commit();
    }
    
    public static boolean getHelpStatus(SharedPreferences preferences)
    {
    	if("yes".equals(preferences.getString(PREFERENCE_HELP, "no")))
    	{
    		return true;
    	}
    	return false;
    }
    
    public static void storeUserNameAndPassword(SharedPreferences preferences,String userName,String password)
    {
    	SharedPreferences.Editor editor=preferences.edit();  
    	editor.putString(PREFERENCE_USER_NAME, userName);
    	editor.putString(PREFERENCE_USER_PASSWORD, password);
    	editor.commit();
    }
    
    public static User getUserNameAndPassword(SharedPreferences preferences)
    {
    	User user = new User();
    	user.setUserName(preferences.getString(PREFERENCE_USER_NAME, null));
    	user.setPassword(preferences.getString(PREFERENCE_USER_PASSWORD, null));
    	
    	return user;
    	
    }
    
}
